﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.Base;
using ERP_RORZE_PERMISSION.Base;
using ERP_RORZE_PRODUCT.Product.DAO;

namespace ERP_RORZE_PRODUCT.Product.Incauhinhmoi
{
    public partial class ctrlShapeList : DevExpress.XtraEditors.XtraUserControl
    {
        DataTable dt;
        ClsIncauhinhDAO clsConfigureDAO = new ClsIncauhinhDAO();
        private LogUtils log;

        public ctrlShapeList()
        {
            InitializeComponent();
            log = new LogUtils();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            clsConstantsFuction.ExportToExcel(gridView1, 1, true);
        }
        void Reload(object sender, EventArgs e)
        {
            dt = clsConfigureDAO.GetAllShape();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }

        private void ctrlShapeList_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_ShapeAdd frmAdd = new frm_ShapeAdd();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.Show();
        }

        private void btnImport_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            frm_ShapeEdit frmEdit = new frm_ShapeEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ShapeID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ShapeID").ToString();
            frmEdit.Show();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btEdit_Click(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            clsConfigureDAO.DeleteShape(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"ShapeID").ToString());

            //write Log
            log.Table = LogConstant.Table.Product.ShapeList;
            log.Task = LogConstant.Task.Delete;
            log.Description = "ShapeID: " + gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ShapeID").ToString();
            log.WriteLog();

            Reload(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            btDelete_Click(sender, e);
        }
    }
}
